#define TRACE
using System;
using System.Diagnostics;

namespace Triton.Common
{
	public class PerformanceTimer : IDisposable
	{
		private readonly Stopwatch stopwatch_0;

		private readonly string string_0;

		private bool bool_0;

		private readonly FinishedMeasuringCallback finishedMeasuringCallback_0;

		public long ElapsedMilliseconds => stopwatch_0.ElapsedMilliseconds;

		public PerformanceTimer(string debugText, FinishedMeasuringCallback callback = null)
		{
			finishedMeasuringCallback_0 = callback;
			stopwatch_0 = new Stopwatch();
			string_0 = debugText;
		}

		public void Start()
		{
			stopwatch_0.Start();
		}

		[Conditional("TIMERS")]
		private void method_0()
		{
			Start();
		}

		[Conditional("TIMERS")]
		private void method_1()
		{
			StopAndPrint();
		}

		public void DontPrint()
		{
			bool_0 = true;
		}

		public void StopAndPrint()
		{
			stopwatch_0.Stop();
			if (!bool_0)
			{
				Trace.WriteLine($"[{stopwatch_0.Elapsed.TotalMilliseconds}ms] {string_0}");
				if (finishedMeasuringCallback_0 != null)
				{
					finishedMeasuringCallback_0.BeginInvoke(ElapsedMilliseconds, null, null);
				}
			}
		}

		public void Dispose()
		{
		}
	}
}
